package com.tanhua.dubbodb.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.model.domain.Question;
import com.tanhua.dubbodb.mapper.QuestionMapper;
import com.tanhua.dubbointerface.api.QuestionApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;

    /**
     *  通过userId查询Question数据库中的记录
     * @param userId
     * @return
     */
    @Override
    public Question findQuestionByUserId(Long userId) {
        QueryWrapper<Question> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return questionMapper.selectOne(queryWrapper);
    }

    /**
     * 修改交友问题
     * @param ques
     */
    @Override
    public void update(Question ques) {
        questionMapper.updateById(ques);
    }

    /**
     * 当查询数据库中的记录为空的时候执行保存操作，
     * @param question
     */
    @Override
    public void save(Question question) {
        questionMapper.insert(question);
    }


}
